﻿package com.dcliment.display.gui
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * Similar to play Pause button but just a regular toggle button
	 *  
	 * @author dcliment
	 * version 1.0
	 * 
	 */	
	public class SimpleToggleButton extends MovieClip implements ISimpleButton
	{
		public static var TOGGLE1:String = "toggle1";
		public static var TOGGLE2:String = "toggle2";
		
		public function SimpleToggleButton()
		{
			this.gotoAndStop(1);
			enable();
		}
		public function toggle1():void
		{
			gotoAndStop(1);
		}
		
		public function toggle2():void
		{
			gotoAndStop(2);
		}
		
		public function enable():void
		{
			this.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
			
			this.mouseEnabled = true;
			this.buttonMode = true;
		}
		
		public function disable():void
		{	
			this.removeEventListener(MouseEvent.CLICK, onClick);
			
			this.mouseEnabled = false;
			this.buttonMode = false;
		}
		
		//
		// Private Functions
		//
		protected function onClick(e:MouseEvent):void
		{
			
			if(this.currentFrame == 1)
			{
				toggle2();
				dispatchEvent(new Event(SimpleToggleButton.TOGGLE2));
			}
			else if(this.currentFrame == 2)
			{
				toggle1();
				dispatchEvent(new Event(SimpleToggleButton.TOGGLE1));
			}
		}
	}
}